package sfsoftware.game.actor;

import sfsoftware.game.TrevorLegacy;
import sfsoftware.game.actor.attributes.Collidable;
import sfsoftware.game.actor.attributes.Wiffable;
import sfsoftware.game.trevor.Player;

/** When the Player comes within a specified proximity of this object, an associated Script is run.
 * 
 * @author Steve Thompson
 */
public class ProximityTriggeredScriptedActor extends ScriptedActor 
{
	private int distanceToTrigger = 0;
	
	public ProximityTriggeredScriptedActor(int destX, int destY, String texture, int destWidth, int destHeight, int srcX, int srcY, String scriptFile, int triggerDistance) 
	{
		super(destX, destY, texture, destWidth, destHeight, srcX, srcY, scriptFile);
		distanceToTrigger = triggerDistance;
	}
	
	@Override
	public void collisionResult(Collidable object) 
	{
		// Copy of Actor method - we override ScriptedActor's method because we ONLY want a 
		// script triggered if they are a certain distance away, not if they "bump" the object.
		if(object.equals(TrevorLegacy.player))
		{
			if(this instanceof Wiffable && Player.isUsingWiffa())
			{
				Wiffable w = (Wiffable) this;
				w.wiffaHit();
			}
		}
	}		
	
	public int getTriggerDistance()
	{
		return distanceToTrigger;
	}
	
	public void setTriggerDistance(int TriggerDistance)
	{
		distanceToTrigger = TriggerDistance;
	}
	
	@Override
	public void update() 
	{
		// Check distance from Player to center coordinates here and trigger script if the requirements are met!
		if(distanceToActor(Player.getPlayer()) <= distanceToTrigger)
		{
			runAssociatedScript();
		}
		
		super.update();
	}
	
}
